#include <stdio.h>
#include <unistd.h>
#include <pthread.h>
#include <string.h>
#include <log.h>
#include <timer.h>

#include "scu.h"

scu_buf_t bufa;

void *writer(void*);

int main(void)
{
  pthread_t w;
  struct in_addr localhost;

  logRegisterThread("main");

  bufa = scuBufferCreate(65536, SCU_BUF_MAX_READERS, NULL);

  pthread_create(&w, NULL, writer, NULL);
  
  localhost.s_addr = inet_addr("127.0.0.1");
  sccTransportCreateTransmitter(&bufa, &localhost, 5745);
  scuBufferUnlock(&bufa);

  pthread_join(w, NULL);

  sleep(1);

  return 0;
}

void *writer(void* dummy)
{
  int i;
  char data[65536];

  logRegisterThread("writer");

  for (i=0; i < 250; i++)
  {
    scuBufferWrite(&bufa, data, 65536, SCU_BUF_BLOCK_ALL);
    //usleep(1000000L);
  }
  scuBufferFinalize(&bufa);

  return NULL;
}
